package com.kefu.admin.modules.tgqmdj.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kefu.admin.modules.tgqmdj.model.Tgctms;
import com.kefu.admin.modules.tgqmdj.service.TgdService;
import com.kefu.admin.utils.R;
import com.kefu.admin.utils.Result;
import com.kefu.admin.utils.SendRequest;
import com.kefu.admin.utils.TokenGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by TWD on 2019/1/28.
 */
@CrossOrigin("http://192.168.110.197:8082")
@RestController
@RequestMapping("/api/mobile")
public class WebApiController {

    private static final Logger logger = LoggerFactory.getLogger(WebApiController.class);

    private Map<String,String> mapToken = new HashMap<>();

    @Autowired
    private TgdService tgdService;



    @PostMapping(value={"/myctsubmit"})
    public R ctsubmit(HttpServletRequest request,@RequestBody Tgctms tgctms){
        try {
            String pwd = request.getParameter("pwd");
            if("4554".equals(pwd)){
                tgdService.saveMyCtMsg(tgctms);
                return  R.ok();
            }else{
                return  R.error("密码错误");
            }

        }catch (Exception ex){
            logger.error("提交留言失败：{}",ex);
        }
        return  R.error("失败");
    }

    @RequestMapping("/loadmyctdata")
    @ResponseBody
        public R loadWenzhang(Tgctms tgctms, Integer limit, Integer offset){
        PageHelper.startPage(offset,limit);
        List<Tgctms> tgctmsList = tgdService.queryMyCtMsg(tgctms);
        PageInfo<Tgctms> pages = new PageInfo<>(tgctmsList);
        return R.ok().put("data",pages);
    }

    @RequestMapping("/loadmyctdataImg")
    @ResponseBody
    public R loadmyctdataImg(Tgctms tgctms, Integer limit, Integer offset){
        PageHelper.startPage(offset,limit);
        List<Tgctms> tgctmsList = tgdService.queryMyCtMsgImg(tgctms);
        PageInfo<Tgctms> pages = new PageInfo<>(tgctmsList);
        return R.ok().put("data",pages);
    }



}
